﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BUS;
using DATA.BusinessObjects;

namespace Presentation
{
    public partial class frmTiepNhanKhachHang : Form
    {
        public frmTiepNhanKhachHang()
        {
            InitializeComponent();
        }

        private void frmTiepNhanKhachHang_Load(object sender, EventArgs e)
        {
            IList<Loaikhach> list = LoaiKhachBUS.LayDanhSachLoaiKhach();

            cbxLoaiKhach.DataSource = list;
            cbxLoaiKhach.DisplayMember = "TenLoaiKhach";
            cbxLoaiKhach.ValueMember = "Id";
        }

        private void btnThem_Click(object sender, EventArgs e)
        {
            Khachhang kh = new Khachhang();
            if (KhachHangBUS.LayKhachHangMoiNhat() != null)
                kh.Id = ThamSoBUS.TaoMaTangTuDong(KhachHangBUS.LayKhachHangMoiNhat().Id, 3, "MKH");
            else
                kh.Id = "MKH1";
            kh.TenKhachHang = txtTenKhachHang.Text;
            kh.Cmnd = txtCMND.Text;
            kh.DiaChi = txtDiaChi.Text;
            kh.Loaikhach = (Loaikhach)cbxLoaiKhach.SelectedItem;

            if(KhachHangBUS.ThemKhachHang(kh))
            {
                MessageBox.Show("Đã thêm thành công!!!");
                ResetForm();
            }
            else
                MessageBox.Show("Không thêm thành công!!!");
        }

        private void btnThoat_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        #region Reset Form
        private void ResetForm()
        {
            txtCMND.Text = txtDiaChi.Text = txtTenKhachHang.Text = "";
            cbxLoaiKhach.Text = "";
        }
        #endregion
    }
}
